/**
 * @list.h
 * This file is part of FEGRF.
 * 
 * FEGRF is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * See LICENSE file in main folder for more information.
 */

#ifndef __LIST_H__
#define __LIST_H__

#include "main.h"

#include <wx/dataview.h>
#include <wx/dnd.h>

enum colID
{
	COL_NAME,
	COL_TYPE,
	COL_SIZE,
	COL_PACK,
	COL_MAX,
};

enum encID
{
	ENC_ANSI = 1,
	ENC_EUC_KR,
	ENC_LOCAL,
};

class MyData
{
public:
	wxString name;
	wxString type;
	long size;
	long pack;
};

WX_DECLARE_LIST(MyData, MyDataList);

class MyListModel : public wxDataViewVirtualListModel
{
public:
	MyListModel(MainFrame *main_frame);

	MainFrame *parent;

	virtual unsigned int GetColumnCount(void) const {
		return COL_MAX;
	}
	virtual wxString GetColumnType(unsigned int column) const {
		return _("string");
	}
	virtual void GetValueByRow(wxVariant &variant, unsigned int row, unsigned int column) const;
	virtual bool GetAttrByRow(unsigned int row, unsigned int column, wxDataViewItemAttr &attr) const;
	virtual bool SetValueByRow(const wxVariant &variant, unsigned int row, unsigned int column);
};

class MyDataViewCtrl : public wxDataViewCtrl
{
public:
	MyDataViewCtrl(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style);

	bool sort_name,
	     sort_type,
	     sort_size,
	     sort_pack;
	char enc_type;
	bool m_editing;

	void Resize(int size);
	void OnRefresh(wxDataViewEvent &event);
	void OnResize(wxSizeEvent &event);
	void OnSorted(wxDataViewEvent &event);
	void OnEditingStart(wxDataViewEvent &event);
	void OnEditingDone(wxDataViewEvent &event);
	void StartEdit(wxDataViewItem item);
	wxDataViewItem GetItem(int row);
	int GetRow(wxDataViewItem item);
	void SetEncoding(int encoding) { enc_type = encoding; }
private:
	unsigned short width;
	wxObjectDataPtr<MyListModel> listmodel;

	DECLARE_EVENT_TABLE()
};

class DnDFile : public wxFileDropTarget
{
	MainFrame *m_parent;
public:
	DnDFile(MainFrame *parent) { m_parent = parent; }
	
	virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &file_names);
};

int CompareName (const MyData** arg1, const MyData** arg2);
int CompareNameX(const MyData** arg1, const MyData** arg2);
int CompareType (const MyData** arg1, const MyData** arg2);
int CompareTypeX(const MyData** arg1, const MyData** arg2);
int CompareSize (const MyData** arg1, const MyData** arg2);
int CompareSizeX(const MyData** arg1, const MyData** arg2);
int ComparePack (const MyData** arg1, const MyData** arg2);
int ComparePackX(const MyData** arg1, const MyData** arg2);

#endif //__LIST_H__
